<template>
  <div id="app">
    <div id="nav" ref="header" :class="{ nav_fixed: isFixed }">
      <blob-header></blob-header>
    </div>
    <template v-if="show">
      <tag-header></tag-header>
    </template>
    <el-container>
      <!-- 内容 -->
      <el-main class="main">
        <el-row>
          <el-col :span="24" class="col3">
            <!-- <transition name="el-fade-in el-fade-in-linear"> -->
            <transition name="el-zoom-in-center el-zoom-in-top">
              <router-view :key="key" />
            </transition>
          </el-col>
        </el-row>
      </el-main>
      <!-- 侧边栏 -->

      <el-aside>
        <transition name="el-zoom-in-center el-zoom-in-top">
          <router-view name="asidemenu"> </router-view>
        </transition>
      </el-aside>
    </el-container>
    <!-- 底栏 -->
    <hr />
    <el-footer height="30px">&copy;ETC大连售前与研发部</el-footer>
  </div>
</template>
<script>
import BlobHeader from "@/components/Header";

import TagHeader from "./components/tagHeader/index.vue";

export default {
  components: {
    BlobHeader,
    TagHeader,
  },
  data() {
    return {
      isFixed: false,
      offsetTop: 0,
      taglist: [],
      show: true
    };
  },
  computed: {
    key() {
      return this.$route.name !== undefined
        ? this.$route.name + +new Date()
        : this.$route + +new Date();
    },
  },
  mounted() {
    // 设置bar浮动阈值为 #fixedBar 至页面顶部的距离
    this.offsetTop = document.querySelector("#nav").offsetTop;
    // 开启滚动监听
    window.addEventListener("scroll", this.handleScroll);
  },
  watch: {
    $route() {
      this.$forceUpdate();
      this.show = this.$route.path == "/reource"|| this.$route.path.indexOf('person') != -1 ? false : true;
    },
  },
  methods: {
    // 滚动监听  滚动触发的效果写在这里
    handleScroll() {
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop >= this.offsetTop + 60) {
        this.isFixed = true;
      } else {
        this.isFixed = false;
      }
    },
  },
  created() {},
  destroyed() {
    // 离开页面 关闭监听 不然会报错
    window.removeEventListener("scroll", this.handleScroll);
  },
};
</script>
<style>
body {
  background-color: rgb(200, 219, 219);
}
aside {
  margin-left: 40px;
  width: 600px;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin: 0;
  min-width: 600px;
  margin: 0 auto;
}
.nav_fixed {
  z-index: 100;
  position: fixed;
  top: 0px;
  box-shadow: 1px 1px 1px wheat;
}
#nav {
  padding: 0px;
  /* position: sticky; */
  width: 100%;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
body {
  margin: 0px;
}
.main {
  background-color: white;
}
.show {
  display: none;
}
</style>
